import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post, Query,
  Req,
  UseGuards,
  UseInterceptors,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiHeader, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';

import { LoggerInterceptor } from '@/interceptor/logger.interceptor';
import { CreateSubmissionDto } from '@/modules/submission/dto/create-submission.dto';
import { ResponseSubmissionDto } from '@/modules/submission/dto/response.submission.dto';
import { UpdateSubmissionDto } from '@/modules/submission/dto/update-submission.dto';

import { SubmissionService } from './submission.service';
import {ListTaskDto} from "@/modules/submission/dto/list.submission.dto";

@ApiTags('智能行政-我的提交')
@ApiHeader({
  name: 'Authorization',
  description: 'token令牌',
  required: true,
})
@ApiBearerAuth()
@UseInterceptors(LoggerInterceptor)
@UseGuards(AuthGuard('jwt'))
@Controller('administrative/my-submission')
export class SubmissionController {
  constructor(private readonly submissionService: SubmissionService) {}

  @Post()
  @ApiOkResponse({ type: CreateSubmissionDto })
  @ApiOperation({ summary: '创建提交任务' })
  create(@Body() createSubmissionDto: CreateSubmissionDto) {
    return this.submissionService.create(createSubmissionDto);
  }

  @Get('/all')
  @ApiOkResponse({ type: ResponseSubmissionDto })
  @ApiOperation({ summary: '根据用户 id 获取提交任务列表' })
  async findAll(@Query() taskList: ListTaskDto) {
    return await this.submissionService.findAllTask(taskList);
  }

  @Get()
  @ApiOkResponse({ type: ResponseSubmissionDto })
  @ApiOperation({ summary: '根据用户 id 获取提交任务列表' })
  findAllUserTask(@Req() req: Request) {
    return this.submissionService.findUserAllTask(req.headers['authorization']);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.submissionService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateSubmissionDto: UpdateSubmissionDto) {
    return this.submissionService.update(+id, updateSubmissionDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.submissionService.remove(+id);
  }
}
